home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / pxtable.h < prev    next >
C/C++ Source or Header  |  1994-10-10  |  5KB  |  107 lines

  1. #ifndef __PX_TABLE_H_
  2. #define __PX_TABLE_H_
  3.  
  4. #include "pxfield.h"
  5.  
  6. //enum KH_SETMODE    { INSERT, REPLACE, APPEND    };
  7. /*
  8. This class incapsulates the Paradox Table data and operations.
  9. Table is initiated with file name and used through handle.
  10. We use one-PC (no net support) in this version.
  11. We intend to use PXTable not as standing-alone class, but as the child
  12. class in scope of this class functions. So we don't need functions for
  13. the access to class data. We also don't need to define the table access
  14. functions - they may be called as func(tblHandle) and so on (no need to
  15. use ClassName.func(ClassName.tblHandle), data and functions are available).
  16. */
  17.  
  18. class AskManager;
  19. class ReportManager;
  20.  
  21. class KH_PXTable
  22.     {
  23.     protected:
  24.     char* fileName;                        // Table file name
  25.     TABLEHANDLE tblHandle;                 // Table handle
  26.     RECORDHANDLE recHandle;                // Record handle
  27.     FIELDHANDLE fldHandle;                 // Field handle
  28.     RECORDNUMBER current;                  // Current record
  29.     RECORDNUMBER nRecords;                 // Total number of records
  30.     int nFlds;                             // Number of fields
  31. /*
  32. KH_SHARE flag is initiated as 1 (one process uses the table).
  33.        If table is on screen and we call AskManager (querry to table),
  34.        then, after querry AskManager will close all tables, exept of
  35.        those, which was on screen before querry. When calling AskManager,
  36.        we increase KH_SHARE, and after the querrying, decrease it, and
  37.        if its value becomes zero, close the table. Not used in this version.
  38. */
  39.     int KH_SHARE;                          // Is it possible to delete
  40.                            // Not used in ver. 1.0
  41.     public:
  42. // Create new or open existing table
  43.     KH_PXTable(char* fName,        // Table name
  44.         int idx = 0,           // Index governs table
  45. // Use last 3 arguments for creating new table.
  46.         int fNo = 0,           // Number of fields in table
  47.         char** fields = NULL,  // Fields names array
  48.         char** types = NULL);  // Fields types array
  49.  
  50.     ~KH_PXTable();  // Close table and free memory. Does not remove file.
  51.  
  52.         int set_file(char* fName);
  53.     TABLEHANDLE getTblHandle() { return tblHandle; }
  54.     RECORDHANDLE getRecHandle() { return recHandle; }
  55.     FIELDHANDLE getFldHandle() { return fldHandle; }
  56. // Class data - not table operations.
  57.     void setFld(int f) { fldHandle = f; }     // Attention!!! No verif.
  58.     void setRec(RECORDHANDLE rec) { recHandle = rec; }
  59.         void setNRecords(int sh) { nRecords += sh; current += sh; }
  60. // Functions to operate on RECORDHANDLE.
  61.     int getField(KH_PXFLD* ret);
  62.     int putField(KH_PXFLD* f);
  63. // Test, if this record and this querry are compatible. 0 (FALSE), 1 (TRUE).
  64.     int testQuerry(char** shablon);
  65. // Get field as string. You can use it for output.
  66.     KH_FIELD_TYPE TranslateField(char* buf);
  67. /* Find function works as simple (one-table) ASK procedure. It uses
  68. shablon - array of strings, containing conditions. Comparison of strings
  69. processed with strcpy functions. Dates are compared as long.
  70. Numbers are compared using simple arithmetic operators.
  71. We use three virtual functions Compare() for comparison operations. The
  72. reason is that in child class could be defined some language, which
  73. permits complex conditions. For example, using Slang class for basic-like
  74. language, we got:
  75. querry:   "< FIELD * 3"
  76. realization:
  77. int Compare(char* shab, double field)
  78.     {
  79.     slang.assign(FIELD, GetField()); // Create Slang variable for field
  80.     slang.process("F =" + shab);     // Run program
  81.     return slang.GetVariable("F") - field;  // 0, +, or -
  82.     }
  83. return 1 (success, not the end of table) or 0 (EOT), or 2 (EOT and success).
  84. In this class only simple conditions (equial / not equial) are realized.
  85. */
  86.     int Find(char** shablon);
  87. // Condition checkers.
  88.     virtual int Compare(char* shab, char* field);    // Strings
  89.     virtual int Compare(char* shab, double field);   // Numbers
  90.     virtual int Compare(char* shab, long field);     // Date and Long
  91.     virtual int Compare(char* shab, short field);    // Short
  92.  
  93. /* AskManager class operates with multitables querries.
  94. If there are more than 1 tables in querry, special "Example" variable(s)
  95. should be set. Each call to AskManager builds new table "Answer".
  96. */
  97.     friend class KH_AskManager;
  98.  
  99. /* The ReportManager class incapsulates reports output. It uses the
  100. text file containing report formating strings. Not used in ver. 1.0
  101. */
  102.     friend class ReportManager;
  103.     };
  104.  
  105. #endif __PX_TABLE_H_
  106.  
  107.